//
//  HJCVisitorView.swift
//  新浪微博Swift
//
//  Created by 郝俊聪 on 15/5/10.
//  Copyright (c) 2015年 heima. All rights reserved.
//

import UIKit



protocol HJCVisirorViewDelegate : NSObjectProtocol{

    
    func clickLoginBtn()
    
    func clickRegisterBtn()

}



class HJCVisitorView: UIView {
    
    weak var delegate:HJCVisirorViewDelegate?

    @IBOutlet weak var iconView: UIImageView!
    
    @IBOutlet weak var rollingView: UIImageView!
    
    @IBOutlet weak var desctextLbl: UILabel!
    
    
    @IBAction func clickRegisterBtn() {
        
        self.delegate?.clickRegisterBtn()
    }

    @IBAction func clickLoginBtn() {
        
        self.delegate?.clickLoginBtn()
    }

    

    
    func setViewInfo(iconName:String, rollingName:String, message:String, isHome:Bool = false)
    {
        
        
        iconView.hidden = !isHome
        
        if isHome
        {
            iconView.image = UIImage(named: iconName)
            rollingView.image = UIImage(named: rollingName)
            
            
        }else
        {
            rollingView.image = UIImage(named: iconName)
            
        }
        
        desctextLbl.text = message
        
        isHome ? beginAnimation() : endAnimation()
        
    }
    
    
    func beginAnimation()
    {
         let anim = CABasicAnimation(keyPath: "transform.rotation")
         anim.toValue = M_PI*2
         anim.duration = 20
         anim.repeatCount = MAXFLOAT
         rollingView.layer .addAnimation(anim, forKey: nil)
    }
    
    func endAnimation()
    {
        rollingView.layer.removeAllAnimations()
    }

}
